//
//  myComstruct.h
//  OpensslTest
//
//  Created by jiahua on 16/3/29.
//  Copyright © 2016年 secsmarts. All rights reserved.
//
//  此类专门封装用来进行数据的加密打包、拆包解密
//

#define _RSA_SYSTEM_
//#define _SM2_SYSTEM_

#ifdef _RSA_SYSTEM_
//#include "openssl/entropy.h"
//#include "openssl/ctr_drbg.h"
//#include "openssl/bignum.h"
#include "openssl/x509.h"
#include "openssl/rsa.h"
#include "openssl/aes.h"
#include "Define.h"
#include "error.h"

#else   //_RSA_SYSTEM_
#include <openssl/ecp.h>
#include <openssl/hmac_drbg.h>
#include "sm2.h"
#include "sm3.h"
#include "sm4.h"
#include "sm2_util.h"
#endif  //_RSA_SYSTEM_

#ifdef _RSA_SYSTEM_

#define RSA_EXPONENT                65537


#endif  //_RSA_SYSTEM_

struct _SecHead_
{
    u16     Token;                                  //包头标识
    u16     Len;                                    //数据长度，不包括包头8字节
    u8		Ver;                                    //协议版本号
    u8		Cmd;                                    //数据包类型
    u16		Cnt;                                    //数据包计数器
    //u8	*Data;
};
typedef struct _SecHead_ SstSecHead;

#define SST_VERSION_SM2         0x10
#define SST_VERSION_RSA         0x20
#define SST_VERSION_SM4         0x30
#define SST_VERSION_AES         0x40
/**
 *  对输入的buff求hash
 *
 *  @param inData
 *  @param inDataLen
 *  @param outHash
 *  @return hash后长度
 */
int GetHash(u8* inData, int inDataLen, u8 *outHash);
int getHelloToDevicePackage(u8 *inData, int inDataLen, u8 *inKey, int inKeyLen, u8 *outData, int *outDataLen);
int getDeviceAnswer(const u8 *inData, int inDataLen, u8 *inKey, int inKeyLen, u8 *outData, int *outDataLen, int type);
int myConstructSecPacketRaw(u8 *inData, int inDataLen, u8 *inKey, int inKeyLen, int *inCnt, u8 SecTrans, u8 cmdTag, u8 *outData, int *outDataLen);
int myDestructSecPacketRaw(u8 *inData, int inDataLen, u8 *inKey, int inKeyLen, int *inCnt, u8 *outData, int *outDataLen);
int isEncryptPackage (u8 *inData);
int CharToByte(const u8 *inBuf, int inLen, u8 *outBuf);
void get_random_bytes(void *buf, size_t len);
void LogHex(const char *inLable, const u8 *inData, int inDataLen);
int isBroadCast(const u8* data);
